package com.example.atiplat_vodcp;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLEncoder;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;


/**
 * com.example.atiplat_vodcp.browExtObj
 * @author Administrator
 *
 */
public class browExtObj {
	public static String getTrace(Throwable t) {
		StringWriter stringWriter = new StringWriter();
		PrintWriter writer = new PrintWriter(stringWriter);
		t.printStackTrace(writer);
		StringBuffer buffer = stringWriter.getBuffer();
		return buffer.toString();
	}

	MainActivity mainActivity;
	
	public browExtObj(MainActivity mainActivity2) {
		mainActivity = mainActivity2;
	}
	@JavascriptInterface  //sdk17�汾���ϼ���ע��    solu  click btn ma fein ..
	public void play() {
		try {

			String mv = "smb://192.168.2.106/e/������/��ͷ����Сͷ�ְ�/�´�ͷ���Ӻ�Сͷ�ְ�֮���ܼƻ�.mp4";
			Log.v("::::mv in html ", mv);
			Toast.makeText(mainActivity,
					"play in html,mv:" + new File(mv).exists(),
					Toast.LENGTH_LONG).show();
			String mv2 = Environment.getExternalStorageDirectory().getPath()
					+ "/Test_Movie.m4v";
			mv="http://127.0.0.1:7788/?file="+URLEncoder.encode(mv,"utf-8");
		//	Log.v("URI html:::::::::", uri.toString());
			Uri uri = Uri.parse(mv);
			// ����ϵͳ�Դ��Ĳ�����
			Intent intent = new Intent(Intent.ACTION_VIEW);
			Log.v("URI html:::::::::", uri.toString());
			// intent.setData(uri);
			intent.setDataAndType(uri, "video/*");
			mainActivity.startActivity(intent);
			System.out.println("--form_load finish");

		} catch (Throwable e) {
			Log.i("::::::::::::exp", getTrace(e));
		}
	}
	
	
	@JavascriptInterface  //sdk17�汾���ϼ���ע��    solu  click btn ma fein ..
	public void play2() {
		try {

			String mv = "";
			Log.v("::::mv in html ", mv);
			Toast.makeText(mainActivity,
					"play in html,mv:" + new File(mv).exists(),
					Toast.LENGTH_LONG).show();
			String mv2 = Environment.getExternalStorageDirectory().getPath()
					+ "/Test_Movie.m4v";
			mv="http://127.0.0.1:7777/?smb="+URLEncoder.encode(mv);
			
			mv="http://192.168.2.114/IMG_1084.mp4";
		//	Log.v("URI html:::::::::", uri.toString());
			Uri uri = Uri.parse(mv);
			// ����ϵͳ�Դ��Ĳ�����
			Intent intent = new Intent(Intent.ACTION_VIEW);
			Log.v("URI in html:::::::::", uri.toString());
			// intent.setData(uri);
			intent.setDataAndType(uri, "video/*");
			mainActivity.startActivity(intent);
			System.out.println("--play2 _load finish");

		} catch (Throwable e) {
			Log.i("::: exp in player2", getTrace(e));
		}
	}
	
	@JavascriptInterface  //sdk17�汾���ϼ���ע��    solu  click btn ma fein ..
	public void play(String url) {
		try {

			String mv = "";
			Log.v("::::mv in html ", mv);
			Toast.makeText(mainActivity,
					"play in html,mv:" + new File(mv).exists(),
					Toast.LENGTH_LONG).show();
			String mv2 = Environment.getExternalStorageDirectory().getPath()
					+ "/Test_Movie.m4v";
			mv="http://127.0.0.1:7777/?smb="+URLEncoder.encode(mv);
			
			mv="http://192.168.2.114/IMG_1084.mp4";
		//	Log.v("URI html:::::::::", uri.toString());
			mv=url;
			Uri uri = Uri.parse(mv);
			// ����ϵͳ�Դ��Ĳ�����
			Intent intent = new Intent(Intent.ACTION_VIEW);
			Log.v("URI in html:::::::::", uri.toString());
			// intent.setData(uri);
			intent.setDataAndType(uri, "video/*");
			mainActivity.startActivity(intent);
			System.out.println("--play2 _load finish");

		} catch (Throwable e) {
			Log.i("::: exp in player2", getTrace(e));
		}
	}
	
	
	public String retStr(String s)
	{
		return "$ret:"+s;
	
	}
	
	@JavascriptInterface  //sdk17�汾���ϼ���ע��    solu  click btn ma fein ..
	public void play3() {
		try {

			String mv = "smb://192.168.2.106/e/������/��ͷ����Сͷ�ְ�/�´�ͷ���Ӻ�Сͷ�ְ�֮���ܼƻ�.mp4";
			Log.v("::::mv in html ", mv);
			Toast.makeText(mainActivity,
					"play in html,mv:" + new File(mv).exists(),
					Toast.LENGTH_LONG).show();
			String mv2 = Environment.getExternalStorageDirectory().getPath()
					+ "/Test_Movie.m4v";
			mv="http://127.0.0.1:7777/?smb="+URLEncoder.encode(mv);
			
			mv="http://localhost/IMG_1084.mp4";
			
			String jpg="smb://192.168.2.106/e/������/��ͷ����Сͷ�ְ�/�´�ͷ���Ӻ�Сͷ�ְ�֮���ܼƻ�.jpg";
			mv="http://127.0.0.1:7788/?file="+URLEncoder.encode(jpg, "utf-8");
		//	Log.v("URI html:::::::::", uri.toString());
			Uri uri = Uri.parse(mv);
			// ����ϵͳ�Դ��Ĳ�����
			Intent intent = new Intent(Intent.ACTION_VIEW,uri);
			intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");   
			Log.v("URI in html:::::::::", uri.toString());
			// intent.setData(uri);
		//	intent.setDataAndType(uri, "/*");
			
		  
            
            
			mainActivity.startActivity(intent);
			System.out.println("--play2 _load finish");

		} catch (Throwable e) {
			Log.i("::: exp in player2", getTrace(e));
		}
	}
	
	
	
}
